﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AmiEmuLib.Host;

namespace amiemu_lib_test
{
    public class ProgressIndicator
    {
        private Thread m_thread;
        public ProgressForm Form = new ProgressForm();

        public ProgressIndicator()
        {
            AutoResetEvent are = new AutoResetEvent(false);

            m_thread = new Thread(() =>
            {
                Application.EnableVisualStyles();
                are.Set();
                Application.Run(Form);
                m_thread = null;
            });

            m_thread.SetApartmentState(ApartmentState.MTA);
            m_thread.Start();
            are.WaitOne();
            are.Close();
        }

        public bool IsDisposed
        {
            get
            {
                return Form.IsDisposed;
            }
        }

        public void AddLine(string a_line)
        {
            Form.Invoke(() => { Form.AddLine(a_line); });
        }

        public void UpdateLastLine(string a_line)
        {
            Form.Invoke(() => { Form.UpdateLastLine(a_line); });
        }

        public string TestName
        {
            get
            {
                return Form.Invoke(() => Form.Text );
            }
            set
            {
                Form.Invoke(() => { Form.Text = value; });
            }
        }

        public void Close()
        {
            Form.Invoke(() => { Form.Close(); });
        }
    }
}
